#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 +10;
int dp[N], n, x, ans, a[N], ans1;
int main(){
	cin >> n;
	for (int i = 1; i <= n; i++ ) {
		cin >> a[i];
		if(dp[i-1] <= 0)dp[i] = a[i];
		else dp[i] = dp[i-1] + a[i];	 
		ans = max(ans, dp[i]);
	}
	cout << ans << '\n';
	return 0;
}
